package com.sm.healthy.ui.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.sm.healthy.R
import com.sm.healthy.base.BaseFragment
import com.sm.healthy.base.handle.TopHandle
import com.sm.healthy.databinding.FragmentBloodGlucoseMeasurementBinding
import com.sm.healthy.device.MedicalProtocol
import com.sm.healthy.model.BloodGlucoseViewModel
import com.sm.healthy.model.MainViewModel
import com.sm.healthy.ui.dialog.BloodOxygenDialog3
import me.hgj.jetpackmvvm.ext.nav
import me.hgj.jetpackmvvm.ext.navigateAction

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER

/**
 * A simple [Fragment] subclass.
 * Use the [BloodGlucoseMeasurementFragment.newInstance] factory method to
 * create an instance of this fragment.
 */
class BloodGlucoseMeasurementFragment :
    BaseFragment<BloodGlucoseViewModel, FragmentBloodGlucoseMeasurementBinding>() {

    private var bloodOxygenDialog3: BloodOxygenDialog3? = null

    override fun layoutId(): Int {
        return R.layout.fragment_blood_glucose_measurement
    }

    override fun initView(savedInstanceState: Bundle?) {

        mDatabind.handle = TopHandle(nav())
        mDatabind.tvEvaluationReference.setOnClickListener {
            bloodOxygenDialog3 =
                activity?.let { it1 -> BloodOxygenDialog3(it1, R.style.BottomDialog) }
            bloodOxygenDialog3?.show()
        }

        mDatabind.click = Click()
    }

    var isStart = true

    inner class Click {

        fun startMeasurement() {
            if (isStart) {
                startMeasure()
                mViewModel.startBtn = "停止测量"
                mDatabind.tvBtnStart.setBackgroundResource(R.drawable.bg_btn_red_shape)
            } else {
                stopMeasure()
                mViewModel.startBtn = "开始测量"
                mDatabind.tvBtnStart.setBackgroundResource(R.drawable.bg_btn_blue_shape)
            }
            mDatabind.bloodGlucose = mViewModel
            isStart = !isStart
        }

        fun goHistory() {
            if (isStart) return mViewModel.toast.postValue("请先停止测量")
            nav().navigateAction(R.id.historyDataFragment)
        }
    }

    /**
     * 开始测量
     */
    private fun startMeasure() {
    }

    private fun stopMeasure() {
    }
}